package med.movyzer.datastructs;

import org.jfree.data.xy.XYSeries;

public class BestShiftCalculator {

	public static int calcShift(int start,int end,int step,MovementSeries mov1, MovementSeries mov2){
		int result=0;
		double bestSimilarity=0;
		for(int i=start;i<end;i+=step){
			mov1.setShift(i);
			double currSimilarity=mov1.getSimilarity(mov2);
			//System.out.println(i+": "+currSimilarity);
			if(currSimilarity>bestSimilarity){
				bestSimilarity=currSimilarity;
				result=i;
			}
		}
		return result;
	}
	
	public static int getShiftSeries(int start,int end,int step,MovementSeries mov1, MovementSeries mov2,XYSeries series){
		
		int bestResult=0;
		double bestSimilarity=0;
		for(int i=start;i<end;i+=step){
			mov1.setShift(i);
			double currSimilarity=mov1.getSimilarity(mov2);
			
			series.addOrUpdate(i, currSimilarity);
			if(currSimilarity>bestSimilarity){
				bestSimilarity=currSimilarity;
				bestResult=i;
			}
		}
		mov1.setShift(0);
		
		return bestResult;
	}
}
